package org.publictransport.server.servlet;

import java.util.ArrayList;
import java.util.List;

import org.publictransport.client.gwt.client.data.TransportLineSerializable;
import org.publictransport.client.gwt.client.stubs.TransportDataGWTService;
import org.publictransport.server.service.data.DataService;
import org.publictransport.server.service.data.TransportLine;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class TransportDataGWTServiceImpl extends RemoteServiceServlet implements TransportDataGWTService{

	@Override
	public void saveTransportData() {
		
		DataService dataService = DataService.getInstance();
		TransportLine line = new TransportLine();
		line.setStartPointLatitude(20d);
		line.setStartPointLongitude(40d);
		line.setEndPointLatitude(11d);
		line.setEndPointLongitude(44d);
		dataService.saveTransportLine(line);
	}

	@Override
	public List<TransportLineSerializable> loadTransportData() {
		DataService dataService = DataService.getInstance();
		List<TransportLine> transportLines = dataService.getTransportLines();
		List<TransportLineSerializable> transportLineSerializables = new ArrayList<TransportLineSerializable>(transportLines.size());
		int i = 0;
		while (i < transportLines.size()) {
			transportLineSerializables.add(transportLines.get(i).getNewTransportLineSerializable());
			i++;
		}
		return transportLineSerializables;
	}
}

